<?php
$pacth="C:/xampp/htdocs/05_NIV/";
require ($pacth.'/Model/ContactModel.php');
require ($pacth.'/Model/MaillerModel.php');			
if(isset($_REQUEST["action"])){
    switch ($_REQUEST["action"]){
        case"insertContact":
            $name		=isset($_REQUEST["name"])?$_REQUEST["name"]:"";
			$email		=isset($_REQUEST["email"])?$_REQUEST["email"]:"";
			$country	=isset($_REQUEST["country"])?$_REQUEST["country"]:"";
			$phone		=isset($_REQUEST["phone"])?$_REQUEST["phone"]:"";
			$address	=isset($_REQUEST["address"])?$_REQUEST["address"]:"";
			$type		=isset($_REQUEST["type"])?$_REQUEST["type"]:"";
			$content	=isset($_REQUEST["content"])?$_REQUEST["content"]:"";
			$name		=str_replace("'","\'",str_replace("\\","\\\\",$name));
			$email		=str_replace("'","\'",str_replace("\\","\\\\",$email));
			$country	=str_replace("'","\'",str_replace("\\","\\\\",$country));
			$phone		=str_replace("'","\'",str_replace("\\","\\\\",$phone));
			$address	=str_replace("'","\'",str_replace("\\","\\\\",$address));
			$type		=str_replace("'","\'",str_replace("\\","\\\\",$type));
			$content	=str_replace("'","\'",str_replace("\\","\\\\",$content));
			//echo "$name \n $email \n $country \n $phone \n $address \n $type \n $content";
			$result=ConntactModule::insertContact($name,$email,$country,$phone,$address,$type,$content);
			if($result){
				$toemail=array(
					array("email"=>"truong@neowiz.vn","name"=>"You")
					//array("email"=>"hieu@neowiz.vn","name"=>"Hoang Trung Hi?u"),
					//array("email"=>"thin@neowiz.vn","name"=>"Vo Th? Thin"),
					//array("email"=>$borrower["email"],"name"=>$borrower["name"])
				);
				$emailbody=getEmailContent($name,$email,$country,$phone,$address,$type,$content);
				$emailtitle="New Contact US";
				sendemail($toemail,$emailtitle,$emailbody);
				echo "true";
			}else{
				echo "fail";
			}
            break;
        case"msg":
            echo '<script>alert("a");</script>';
            break;
        
    }
}
function getEmailContent($name,$email,$country,$phone,$address,$type,$content){
        
        $email_content="";
        $email_content.='
	<div style="
		border:1px solid #ebebeb;
		padding:12px;
		width:624px;
		background-color:#fff;
		">
		<span style="color: #7D7D7D;
				font-size: 11px;
				font-family: tahoma;

				line-height: 16px;">
			<b style="padding:8px 0">Contact US</b>
			<table>
				<tr>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;">
						Name :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$name.'
					</td>
					<th style="color: #7D7D7D;
					font-size: 11px;
					text-align:left;
					font-family: tahoma;
					line-height: 16px;">
						Email :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$email.'
					</td>
				</tr>
				<tr>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;">
						Country :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$country.'
					</td>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;">
						Phone :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$phone.'
					</td>
				</tr>
				<tr>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;">
						Address :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$address.'
					</td>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;">
						Type :
					</th>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					line-height: 16px;">
						'.$type.'
					</td>
				</tr>
				<tr>
					<th style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;" colspan=3>
						Content :
					</th>
				</tr>
				<tr>
					<td style="color: #7D7D7D;
					font-size: 11px;
					font-family: tahoma;
					text-align:left;
					line-height: 16px;" colspan=3>
						<pre style="
								padding:8px;
								margin:0;
								font-size: 11px;
								font-family: tahoma;
								border:1px solid #d7d7d7;
								width:100%;
								"
							>'.$content.'</pre>
					</td>
				</tr>
			</table>
		</span>
	</div>
	
        ';
    return $email_content;
}
?>
